import 'package:aero_frisbee/core/tools/af_log_manager.dart';
import 'package:aero_frisbee/pages/modues/videos/views/af_bottom_sheet_view.dart';
import 'package:flutter/material.dart';

class AfMoreActionSheet extends StatelessWidget {
  const AfMoreActionSheet({
    Key? key,
    this.onFollowClick,
    this.onBlackClick,
    required this.isFriend,
    this.isBlock = false,
    this.onReportClick,
  }) : super(key: key);
  final Function()? onFollowClick;
  final Function()? onBlackClick;
  final Function()? onReportClick;
  final bool isFriend;
  final bool isBlock;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          AfMoreActionItemCell(
            title: isFriend ? 'UnFollow' : 'Follow',
            onTap: () {
              Navigator.of(context).pop();
              onFollowClick?.call();
            },
          ),
          AfMoreActionItemCell(
            title: isBlock ? 'UnBlock' : 'Block',
            onTap: () {
              if (!isBlock) {
                AFLogPvManger.stat(page: AFLogPages.block);
              }
              Navigator.of(context).pop();
              onBlackClick?.call();
            },
          ),
          AfMoreActionItemCell(
            title: 'Report',
            isShowIndicator: false,
            onTap: () {
              AFLogPvManger.stat(page: AFLogPages.report);
              Navigator.of(context).pop();
              onReportClick?.call();
            },
          ),
          Container(
            decoration: const BoxDecoration(
              color: Color(0xffF7F8FA),
            ),
            height: 10,
          ),
          AfMoreActionItemCell(
            title: 'Cancel',
            isShowIndicator: false,
            onTap: () {
              Navigator.of(context).pop();
            },
          ),
          SizedBox(
            height: MediaQuery.of(context).padding.bottom,
          ),
        ],
      ),
    );
  }
}

showAfMoreActionSheet(
  BuildContext context, {
  Function()? onFollowClick,
  Function()? onBlackClick,
  Function()? onReportClick,
  required bool isFriend,
  required bool isBlock,
}) {
  showUpBottomSheetView(
    context,
    contentColor: Colors.transparent,
    child: AfMoreActionSheet(
      onFollowClick: onFollowClick,
      onBlackClick: onBlackClick,
      onReportClick: onReportClick,
      isFriend: isFriend,
      isBlock: isBlock,
    ),
  );
}

class AfMoreActionItemCell extends StatelessWidget {
  const AfMoreActionItemCell({
    Key? key,
    required this.title,
    this.onTap,
    this.isShowIndicator = true,
  }) : super(key: key);
  final String title;
  final Function()? onTap;
  final bool isShowIndicator;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 17),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Align(
                  alignment: Alignment.topCenter,
                  child: Text(
                    title,
                    style: const TextStyle(
                      color: Color(0xff404040),
                      fontWeight: FontWeight.normal,
                      fontSize: 17,
                    ),
                    textAlign: TextAlign.center,
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                  ),
                )
              ],
            ),
          ),
          Visibility(
            visible: isShowIndicator,
            child: Container(
              decoration: BoxDecoration(
                color: const Color(0xff3C3C43).withOpacity(0.36),
              ),
              height: 0.33,
            ),
          )
        ],
      ),
    );
  }
}
